package pers.kw.message.server.service;


import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import pers.kw.enums.YesOrNoEnum;
import pers.kw.message.dto.znx.ZnxReqDto;
import pers.kw.message.server.persist.dao.MessageZnxDao;
import pers.kw.message.server.persist.entity.MessageZnxDO;
import pers.kw.utils.DoWrapUtil;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
public class MessageService {

    @Resource
    private MessageZnxDao messageZnxDao;

    public List<MessageZnxDO> listZnxByApplyId(String applyId) {
        return messageZnxDao.listByApplyId(applyId);
    }

    @Transactional(rollbackFor = Exception.class)
    public void addZnx(ZnxReqDto reqDto) {
        MessageZnxDO znxDO = new MessageZnxDO();
        znxDO.setTitle(reqDto.getTitle());
        znxDO.setApplyId(reqDto.getApplyId());
        znxDO.setContent(reqDto.getContent());
        znxDO.setReadUserNo(reqDto.getUserNo());
        znxDO.setReadStatus(YesOrNoEnum.NO.getCode());
        DoWrapUtil.insert(znxDO, false, false);
        messageZnxDao.save(znxDO);
    }
}
